package com.dp.iot.admin.api.iotwarningnotify;

import com.dp.iot.core.service.CommonRestController;
import org.springframework.beans.factory.InitializingBean;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.math.*;
import java.util.List;
import java.util.Map;
import com.dp.iot.core.common.constant.PageConstant;
import com.dp.iot.core.common.exception.BusinessException;
import com.dp.iot.core.serialize.ResponseMsg;
import com.dp.iot.model.IotWarningNotify;
import com.dp.iot.service.iotwarningnotify.service.IotWarningNotifyService;

import com.dp.iot.core.utils.ListUtil;
import com.dp.iot.core.utils.MapUtil;
import com.dp.iot.core.utils.StringUtil;


/**
* 代码为自动生成 Created by www.magicalcoder.com
* 如果你改变了此类 read 请将此行删除
* 欢迎加入官方QQ群:323237052
*/

@RequestMapping("/admin/iot_warning_notify_rest/")
@RestController
public class AdminIotWarningNotifyRestController extends CommonRestController<IotWarningNotify,String> implements InitializingBean
{

    @Resource
    private IotWarningNotifyService iotWarningNotifyService;

    //分页查询
    @RequestMapping(value={"page"}, method={RequestMethod.GET})
    public ResponseMsg page(
        @RequestParam(required = false,value ="warningNotifyIdFirst")                            String warningNotifyIdFirst ,
        @RequestParam(required = false,value ="collectionPointIdFirst")                            String collectionPointIdFirst ,
        @RequestParam(required = false,value ="warningNotifyNameFirst")                            String warningNotifyNameFirst ,
        @RequestParam(required = false,value ="warningNotifyTypeFirst")                            String warningNotifyTypeFirst ,
        @RequestParam(required = false,value ="warningNotifyParameter1First")                            String warningNotifyParameter1First ,
        @RequestParam(required = false,value ="warningNotifyParameter2First")                            String warningNotifyParameter2First ,
        @RequestParam(required = false,value ="warningNotifyParameter3First")                            String warningNotifyParameter3First ,
        @RequestParam(required = false,value ="warningNotifyContentFirst")                            String warningNotifyContentFirst ,
        @RequestParam(required = false,value ="remarksFirst")                            String remarksFirst ,
        @RequestParam(required = false,value ="creationTimeFirst")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date creationTimeFirst ,
        @RequestParam(required = false,value ="creationTimeSecond")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date creationTimeSecond ,
        @RequestParam(required = false,value ="creationUserFirst")                            String creationUserFirst ,
        @RequestParam(required = false,value ="updateTimeFirst")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date updateTimeFirst ,
        @RequestParam(required = false,value ="updateTimeSecond")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date updateTimeSecond ,
        @RequestParam(required = false,value ="updateUserFirst")                            String updateUserFirst ,
        @RequestParam(required = false,value ="spare1First")                            String spare1First ,
        @RequestParam(required = false,value ="spare2First")                            String spare2First ,
        @RequestParam(required = false,value ="spare3First")                            String spare3First ,
        @RequestParam int page,@RequestParam int limit,@RequestParam(required = false) String safeOrderBy)
    {
        limit = Math.min(limit, PageConstant.MAX_LIMIT);
        int start = (page - 1) * limit;
        Map<String,Object> query = new HashedMap();
        query.put("warningNotifyIdFirst",coverBlankToNull(warningNotifyIdFirst));
        query.put("collectionPointIdFirst",coverBlankToNull(collectionPointIdFirst));
        query.put("warningNotifyNameFirst",coverBlankToNull(warningNotifyNameFirst));
        query.put("warningNotifyTypeFirst",coverBlankToNull(warningNotifyTypeFirst));
        query.put("warningNotifyParameter1First",coverBlankToNull(warningNotifyParameter1First));
        query.put("warningNotifyParameter2First",coverBlankToNull(warningNotifyParameter2First));
        query.put("warningNotifyParameter3First",coverBlankToNull(warningNotifyParameter3First));
        query.put("warningNotifyContentFirst",coverBlankToNull(warningNotifyContentFirst));
        query.put("remarksFirst",coverBlankToNull(remarksFirst));
        query.put("creationTimeFirst",creationTimeFirst);
        query.put("creationTimeSecond",creationTimeSecond);
        query.put("creationUserFirst",coverBlankToNull(creationUserFirst));
        query.put("updateTimeFirst",updateTimeFirst);
        query.put("updateTimeSecond",updateTimeSecond);
        query.put("updateUserFirst",coverBlankToNull(updateUserFirst));
        query.put("spare1First",coverBlankToNull(spare1First));
        query.put("spare2First",coverBlankToNull(spare2First));
        query.put("spare3First",coverBlankToNull(spare3First));
        Integer count = iotWarningNotifyService.getModelListCount(query);
        query.put("start",start);
        query.put("limit",limit);
        if(StringUtil.isBlank(safeOrderBy)){
            query.put("notSafeOrderBy","warning_notify_id desc");
        }else{
            query.put("safeOrderBy",safeOrderBy);
        }
        return new ResponseMsg(count,iotWarningNotifyService.getModelList(query));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.commonService = iotWarningNotifyService;
        super.primaryKey = "warningNotifyId";//硬编码此实体的主键名称
    }
}
